package com.ysd.Dao.Impl;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import com.ysd.entity.Company;
import com.ysd.util.DBmanager;

public class CompanyDaoImpl {
	public Company getCompany() {
		
		Connection conn = DBmanager.getConnection();
		Statement st = null;
		ResultSet rs = null;
		Company company =null;
		try {
			st = conn.createStatement();
			rs = st.executeQuery("select * from company");
			while(rs.next()) {
				String  name = rs.getString("name");
				String webSite = rs.getString("webSite");
				String introduction = rs.getString("introduction");
				String phone = rs.getString("phone");
				String email = rs.getString("email");
				String address = rs.getString("address");
				String cultrue = rs.getString("cultrue");
				String introducePicture = rs.getString("introducePicture");
				String introductBigPicture = rs.getString("introductBigPicture");
				String corporateCulture = rs.getString("corporateCulture");
				String jxPicture = rs.getString("jxPicture");
				 company = new Company(name,webSite,introduction,phone,email,address,cultrue,introducePicture,introductBigPicture,corporateCulture,jxPicture);
			}
			return company;
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}finally {
			DBmanager.closeAll(conn, st, rs);
		}
	}
	/**
	 * 修改公司信息
	 * @param c
	 * @return
	 */
	public int editCompany(Company c) {
		String sql = "UPDATE company set name = '"+c.getName()+"',webSite='"+c.getWebSite()+"', introduction='"+c.getIntroduction()+"',phone='"+c.getPhone()+"',email='"+c.getEmail()+"',address='"+c.getAddress()+"',cultrue='"+c.getCultrue()+"',introducePicture='"+c.getIntroducePicture()+"'  where 1=1 ";
		System.out.println(sql);
		return DBmanager.executeUpdate(sql);
	}
}
